package com.techstar.mqttprocesser.service.mqtt.handler.message;

import com.techstar.mqttprocesser.service.mqtt.handler.message.MessageHandler;
import com.techstar.mqttprocesser.service.mqtt.model.TopicType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author lilei
 * @create 2025-03-27-2025/3/27
 */
@Component
public class MessageHandlerFactory {

    @Autowired
    private List<MessageHandler> messageHandlers;

    public MessageHandler getMessageHandler(TopicType topicType) {
        for (MessageHandler messageHandler : messageHandlers) {
            if (messageHandler.getTopicType() == topicType) {
                return messageHandler;
            }
        }
        return null;
    }

}
